<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>申请双列管</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <style>
        .discell {
            text-align: right;
            width: 180px;
        }

        .input {
            width: 150px;
        }
    </style>
</head>
<body>
<div class="mini-fit">
    <div style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <form id="form1" method="post" style="margin-left: 40px;">
            <input name="mid" id="mid" class="mini-hidden" style="width: 100%" readonly/>
            <input name="priNum" id="priNum" class="mini-hidden" style="width: 100%" readonly/>
            <input name="sex" id="sex" class="mini-hidden" style="width: 100%" readonly/>
            <input name="pname" id="pname" class="mini-hidden" style="width: 100%" readonly/>
            <input name="villid" id="villid" class="mini-hidden" style="width: 100%" readonly/>
            <br>
            <table style="height: 100%;width: 100%;">
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>申请时间:</td>
                    <td class="input" colspan="2">
                        <input property="editor" class="mini-datepicker" id="shenDate" name="shenDate" value="${shenDate}" emptyText = "请选择日期" required="true"
                               nullValue="null" format="yyyy-MM-dd" showTime="true"
                               showOkButton="true" enabled="false" showClearButton="false" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>申请原因:</td>
                    <td class="input" colspan="2" >
                        <input name="shenReason" id="shenReason" class="mini-textarea" emptyText = "申请原因" required="true"
                        style="width: 300px"/>
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">租房合同:</td>
                    <td style="font-size: 10px;">
                        <input type="button" value="上传文件" onclick="onFileUpload('zf')">
                        <span id="msg"></span>
                        <div><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</div>
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">工作合同:</td>
                    <td style="font-size: 10px;">
                        <input type="button" value="上传文件" onclick="onFileUpload('gz')">
                        <span id="msg1"></span>
                        <div><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</div>
                    </td>
                </tr>
            </table>
        </form>
        <div style="padding:2px;margin: 0 auto;text-align: center">
            <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">确定</a>
            <a class="mini-button" iconCls="fa-save" plain="true" onclick="close('close')">取消</a>
        </div>
    </div>
</div>
<script type="text/javascript">

    mini.parse();
    var form = new mini.Form("form1");
    var mid = mini.get("mid");
    var priNum = mini.get("priNum");
    var sex = mini.get("sex");
    var pname = mini.get("pname");
    var villid = mini.get("villid");
    var shenDate = mini.get("shenDate");
    var shenReason = mini.get("shenReason");

    // 保存数据
    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        var json = mini.encode(data);

        // 点击确定按钮,增加二次弹框
        mini.confirm("确定要申请双列管?","确定?",function (action){
            if (action == "ok"){
                $.ajax({
                    url : "/azbj/azbjgl/slg/hjdapply/save",
                    data : {data: json},
                    type : "post",
                    success: function (success){
                        if(success.code == 1){
                            mini.alert("申请成功","信息提示",function () {
                                window.CloseOwnerWindow('ok');
                            });
                        }else if(success.code == 2){
                            mini.alert(success.data);
                        } else if (success.code == 5599) {
                            mini.alert(success.message);
                        } else{
                            mini.alert("申请失败");
                        }
                    }
                });
            }else {
                return;
            }
        })
    }

    function setData() {
        $.ajax({
            url: "/azbjgl/slgapply/getinfo?priNum=" + priNum.getValue(),
            type: "post",
            dataType: "json",
            success: function (hjdata) {
                shenReason.setValue(hjdata.shenReason);
            }
        });
    }

    // 页面一加载
    window.onload = function () {
        // 租房合同
        $("#msg").text("上传成功" + ${count} + "条!");
        $("#msg1").text("上传成功" + ${count1} + "条!");
        villid.setValue(${villid!''});
        mid.setValue(${id!''});
        priNum.setValue(${priNum!''});
        //sex.setValue(${sex!''});
        pname.setValue(${pname!''});
        if("${sex!''}" == "男"){
            sex.setValue(1);
        }else if("${sex!''}" == "女"){
            sex.setValue(2);
        }
        setData();
    }

    function onFileUpload(e) {
        // 业务标识(2头像 3指纹 4改造表现 5心里健康 6购房合同 7租房合同 8工作合同 9其他证明材料)
        var midval = mid.getValue();
        var prival = priNum.getValue();
        var taskid = "";
        if(e == "gf"){
            taskid = "6";
        }else if(e == "zf"){
            taskid = "7";
        }else if(e == "gz"){
            taskid = "8";
        }
        // 拼接字符串
        var url = "/upload/user/uploadAppendixfile/view?1=1&id="+midval+"&priNum="+prival+"&taskId=" + taskid;
        // 工作合同
        if (e == "gz") {
            commonEdit(url, null, null, 600, 400, true, true, true, callback);
            // 回调函数
            function callback() {
                // alert(midval);
                $.ajax({
                    url: "/upload/downloadAppendixFile/getCountById?1=1&priNum="+prival+"&taskId=8" + "&id="+midval,
                    type: "get",
                    success: function (success) {
                        $("#msg1").text("上传成功" + success.data + "条!");
                    }
                })
                grid.reload();
            }
        } else if (e == "zf") {
            commonEdit(url, null, null, 600, 400, true, true, true, callback);
            // 回调函数
            function callback() {
                $.ajax({
                    url: "/upload/downloadAppendixFile/getCountById?1=1&priNum="+prival+"&taskId=7" + "&id="+midval,
                    type: "get",
                    success: function (success) {
                        $("#msg").text("上传成功" + success.data + "条!");
                    }
                })
                grid.reload();
            }
        }
    }

    // 点击取消按钮
    function close(action){
        if(window.CloseOwnerWindow){
            window.CloseOwnerWindow(action);
        }else{
            window.close();
        }
    }

    // 获取页面的id priNum等
    function GetData() {
        var idval = mid.getValue();
        var priNum1 = priNum.getValue();
        var data = {priNum: priNum1, id: idval, taskId: ['7','8']};
        return data;
    }
</script>
</body>
</html>